const app = new Vue({
  el: '#app',
  data: {
    books: [
      {
        id: 1,
        name: '《编程珠玑》',
        data: '2008-01',
        price: '99.00',
        number: 1,
      }, {
        id: 2,
        name: '《编程思想》',
        data: '2002-11',
        price: '89.00',
        number: 1,
      }, {
        id: 3,
        name: '《深入理解计算机原理》',
        data: '2001-06',
        price: '101.00',
        number: 1,
      }, {
        id: 4,
        name: '《算法导论》',
        data: '2010-03',
        price: '66.00',
        number: 1,
      },
    ]
  },
  computed: {
    totalPrice() {
      let totalPrice = 0;
      this.books.reduce(function (preValue, n) {
        return totalPrice = preValue + n.price * n.number;
      },0)
      return totalPrice;
    }
  },
  methods: {
    getToFixed(price) {
      return '￥' + parseFloat(price).toFixed(2);
    },
    decrement(index) {
      return this.books[index].number--;
    },
    increment(index) {
      return this.books[index].number++;
    },
    getRemove(index) {
      this.books.splice(index, 1);
    }
  },
  filters: {
    filterPrice(price) {
      return '￥' + parseFloat(price).toFixed(2);
    }
  }
})